%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 595 842
%%Title: ccalendar.ps
%%Creator: Masayuki Ataka
%%CreationDate: Sun Dec 23 21:53:18 2007
%%EndComments

64 dict begin

/Year 2008 def
/offset_year 2 def

/inner_radius 80 def
/outer_radius 250 def
/column_day 7 def

/color_sunday   { 1 0 0 } def
/color_saturday { 0.9 0 0 } def
/color_bg       { 1 1 1 } def
/color_out      { 0.75 0.75 0.75 } def
/color_zebra    { 1 1 0 } def

/day_of_month      [ 31 28 31 30 31 30 31 31 30 31 30 31 ] def
/day_of_month_leap [ 31 29 31 30 31 30 31 31 30 31 30 31 ] def

/day_of_year_noleap [ 0 0 31 59 90 120 151 181 212 243 273 304 334 365 ] def
/day_of_year_leap   [ 0 0 31 60 91 121 152 182 213 244 274 305 335 366 ] def
/day_of_year {
  Year 4 mod 0 eq % Fixme
  {day_of_year_leap} {day_of_year_noleap}
  ifelse
} def

/column_num 365 7 add column_day div def

/d outer_radius inner_radius sub def
/l d column_day div def
/phi 360 column_num div def
/nphi phi neg def

/circ  { 0 0  3 -1 roll  0 360 arc  } def
/circn { 0 0  3 -1 roll  0 360 arcn } def

/day {
  /theta exch def
  /r exch def
  /rl { r l add } def
  gsave
    newpath
    theta neg rotate
    0 0 rl nphi 0 arc
    r 0 lineto
    0 0 r  0 nphi arcn
    closepath
    fill
  grestore
} def

/date2day_year {
  /dd exch def % day
  /mm exch def % month
  dd
  day_of_year mm get add
  offset_year add
} def

/day_year2r_theta {
  /day_year exch def
  day_year column_day mod l mul inner_radius add
  day_year column_day idiv phi mul
} def

/date_fill { date2day_year day_year2r_theta day } def

%% Pathtext from Blue Book - Program 11

/pathtextdict 26 dict def

/pathtext
{
  pathtextdict begin
    /offset exch def
    /str exch def
    /pathdist 0 def
    /setdist offset def
    /charcount 0 def
    gsave
      flattenpath
      {movetoproc} {linetoproc}
      {curvetoproc} {closepathproc}
      pathforall
    grestore
    newpath
  end
} def

pathtextdict begin
/movetoproc
{
  /newy exch def
  /newx exch def
  /firstx newx def
  /firsty newy def
  /ovr 0 def
  newx newy transform
  /cpy exch def
  /cpx exch def
} def

/linetoproc
{
  /oldx newx def
  /oldy newy def
  /newy exch def
  /newx exch def
  /dx newx oldx sub def
  /dy newy oldy sub def
  /dist dx dup mul dy dup mul add sqrt def
  dist 0 ne
  { % if
    /dsx dx dist div ovr mul def
    /dsy dy dist div ovr mul def
    oldx dsx add oldy dsy add transform
    /cpy exch def
    /cpx exch def
    /pathdist pathdist dist add def
    { % loop
      setdist pathdist le
      { % if-then
	charcount str length lt
        {setchar} {exit} ifelse } 
      { % else
	/ovr setdist pathdist sub def
        exit }
      ifelse
    } loop
  } if
} def

/curvetoproc
{
  (ERROR: No curveto's after flattenpath!) print
} def

/closepathproc
{
  firstx firsty linetoproc
  firstx firsty movetoproc
} def

/setchar
{
  /char str charcount 1 getinterval def
  /charcount charcount 1 add def
  /charwidth char stringwidth pop def
  gsave
    cpx cpy itransform translate
    dy dx atan rotate
    0 0 moveto char show
    currentpoint transform
    /cpy exch def
    /cpx exch def
  grestore
  /setdist setdist charwidth add def
} def
end % pathtextdict

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% Misc Functions
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
/center {
    dup stringwidth
    exch 2 div neg
    exch 2 div neg
    rmoveto
} bind def


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
297 400 translate
90 rotate
gsave

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% Circle Calendar - Main
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%
%% Color
%%

% Zebra Color
gsave
  color_zebra setrgbcolor
  1 2 12 {
    /i exch def
    day_of_year i get offset_year 1 add add
    1
    day_of_year i 1 add get offset_year add
    {
      day_year2r_theta day
    } for
  } for
grestore

% Color of Saturday
newpath
inner_radius l l add add circ
gsave
  color_saturday setrgbcolor fill
grestore

% Color of Sunday
newpath
inner_radius l add circ
gsave
  color_sunday setrgbcolor fill
grestore

% Holiday
gsave
  color_sunday setrgbcolor
  1 1 date_fill
  1 14 date_fill
  2 11 date_fill
  3 20 date_fill
  4 29 date_fill
  5 3 date_fill
  5 4 date_fill
  5 5 date_fill
  5 6 date_fill
  7 21 date_fill
  9 15 date_fill
  9 23 date_fill
  10 13 date_fill
  11 3 date_fill
  11 23 date_fill
  11 24 date_fill
  12 23 date_fill
grestore

% Not this year
gsave
  color_out setrgbcolor
  0 1 offset_year {
    day_year2r_theta day
  } for
  offset_year 366 add 1 370 {
    day_year2r_theta day
  } for
grestore

% Inner Circle for Title(Year)
newpath
inner_radius circ
gsave
  color_bg setrgbcolor fill
grestore
%%
%% Border
%%
inner_radius circ stroke
outer_radius circ stroke

% Weeks
0 phi 360 {
  gsave
    newpath
    neg rotate
    inner_radius 0 moveto
    d 0 rlineto
    stroke
  grestore
} for

% Day of week
inner_radius l outer_radius {
  newpath
  circ
  stroke
} for

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% Circle Calendar - Title
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

/Palatino-Bold findfont 36 scalefont setfont
newpath
0 0 outer_radius l .5 mul add 360 0 arcn
%( January February March April  May  June  July\
%  August September October November December)
(
  Jan     
  Feb     
  Mar    
  Apr     
  May     
  Jun      
  Jul     
  Aug     
  Sep     
  Oct      
  Nov    
  Dec
)
20 pathtext

/Helvetica-Narrow-Bold findfont 14 scalefont setfont
/to_date
{
  date2day_year day_year2r_theta
  neg phi sub rotate
  1 add 2 moveto
} def
/tmp 20 string def
/print_date
{
  /dd exch def
  /mm exch def
  gsave
    mm dd to_date
    mm tmp cvs show
    (/) show
    dd tmp cvs show
  grestore
} def

% Print the first date of the month
1 1 12 {
  1 print_date
} for 

/AvantGarde-Demi findfont 36 scalefont setfont
gsave
  -90 rotate
  0 0 moveto
  (2008) center show
grestore



grestore

end
showpage
%%EOF
